home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / os2 / wuz11a.zip / INST-WUZ.CMD < prev    next >
OS/2 REXX Batch file  |  1994-02-07  |  12KB  |  369 lines

  1. /* Rexx install program */
  2. /* (c) Copyright 1994 Scott Maxwell. */
  3.  
  4. /* Note: I believe this to be a pretty intelligent install routine. */
  5. /*       If anyone wants to use it you can as long as you just      */
  6. /*     credit me as the original author.  Please don't modify the */
  7. /*     top seven lines of this file.                    */
  8.  
  9. Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  10. Call SysLoadFuncs
  11.  
  12. arg where tempdir
  13.  
  14. KeepCommandLineWindow = 1
  15. WaitForUnzip  = 1
  16. UnzipInCommandLineWindow = 1    /* KeepCommandLineWindow must be 1 for this */
  17.  
  18.   Say "Welcome to Workplace UnZip!"'0a'x
  19.  
  20.   Say "WUZ is a series of REXX functions to give you access to archive"
  21.   Say "files (including .ARC, .ARJ, .LZH, .TAR, .Z, .ZIP and .ZOO) from"
  22.   Say "the Workplace Shell or the command line."'0a'x
  23.  
  24. top:
  25.  
  26. ucnt = 1
  27. final = ''
  28.  
  29. if where = '' | tempdir = '' then do
  30.   where = ''
  31.   path = Value('PATH',,'OS2ENVIRONMENT')
  32.  
  33.   Say "WUZ must be installed in a directory on your PATH:"'0a'x
  34.   i = 1
  35.   found = 0
  36.   dir. = ''
  37.   do forever
  38.     parse var path dir.i ';' path
  39.     if Right(dir.i,1) \= '\' then
  40.       dir.i = dir.i'\'
  41.     if SubStr(dir.i,2,1) = ':' then do
  42.       if Length(CharIn(dir.i'wuz.cmd',1,1)) = 1 then do
  43.         found=i
  44.         Call LineIn dir.found'wuz.cmd'
  45.         Call LineIn dir.found'wuz.cmd'
  46.         Call LineIn dir.found'wuz.cmd'
  47.         Call LineIn dir.found'wuz.cmd'
  48.         old = LineIn(dir.found'wuz.cmd')
  49.         if Left(old,8) \= 'DestPath' then do
  50.           preamble = "A version of WUZ.CMD I don't recognize"
  51.       old = ''
  52.       end
  53.         else do
  54.           old = SubStr(old,13,Length(old)-13)
  55.       preamble = 'WUZ'
  56.           Call LineIn dir.found'wuz.cmd'
  57.           Call LineIn dir.found'wuz.cmd'
  58.           hold = LineIn(dir.found'wuz.cmd')
  59.           if Left(hold,24) = 'KeepCommandLineWindow = ',
  60.              & (SubStr(hold,25,1) = '0' | SubStr(hold,25,1) = '1') then
  61.             KeepCommandLineWindow = SubStr(hold,25,1)
  62.           hold = LineIn(dir.found'wuz.cmd')
  63.           if Left(hold,15) = 'WaitForUnzip = ',
  64.              & (SubStr(hold,16,1) = '0' | SubStr(hold,16,1) = '1') then
  65.             WaitForUnzip = SubStr(hold,16,1)
  66.           hold = LineIn(dir.found'wuz.cmd')
  67.           if Left(hold,27) = 'UnzipInCommandLineWindow = ',
  68.              & (SubStr(hold,28,1) = '0' | SubStr(hold,28,1) = '1') then
  69.             UnzipInCommandLineWindow = SubStr(hold,28,1)
  70.         end
  71.     Call LineOut dir.found'wuz.cmd'
  72.     if Length(CharIn(dir.found'Post-WUZ.cmd',1,1)) = 1 then do
  73.       Call Linein(dir.found'Post-wuz.cmd')
  74.       Call Linein(dir.found'Post-wuz.cmd')
  75.       Call Linein(dir.found'Post-wuz.cmd')
  76.       final = Linein(dir.found'Post-wuz.cmd')
  77.       if Left(final,12)\='FinalCommand' | Right(final,3) = "=''" then
  78.         final=''
  79.       ucnt = 1
  80.       user.ucnt = Linein(dir.found'Post-wuz.cmd')
  81.       if Left(user.ucnt,11) = '/* ---- You' then
  82.       do ucnt=2 to 50
  83.         user.ucnt = Linein(dir.found'Post-wuz.cmd')
  84.         if Left(user.ucnt,12) = '/* ---- They' then leave
  85.       end
  86.     end
  87.     Call LineOut dir.found'Post-wuz.cmd'
  88.       end
  89.       i=i+1
  90.     end
  91.     if path='' then leave
  92.   end
  93.  
  94.   if found > 0 then
  95.   do forever
  96.     Say preamble "seems to be installed in" dir.found'0a'x
  97.     Say "0) Use the current copy (i.e. aborting this install)"
  98.     Say "1) Copy over the current version"
  99.     Say "2) Remove the current copy of WUZ and install somewhere else"
  100.     Say "3) Remove every last trace of WUZ from your computer"'0a'x
  101.     Call CharOut ,"What would you like to do: "
  102.     parse upper pull ans
  103.     if ans = 0 | ans = '' then exit(0)
  104.     if ans < 0 | ans > 3 then do
  105.       say '0a'x"Please answer either 0, 1, 2, 3 or <RETURN>"
  106.       iterate
  107.     end
  108.  
  109.     if ans>=2 then do
  110.       say "Erasing:    wuz.cmd"
  111.       say "        wuz.ico"
  112.       say "        post-wuz.cmd"
  113.       say "        zipstrip.cmd"
  114.       say "        zip-dir.cmd"
  115.       say "        zip-dir.ico"
  116.       say "        fldzip.ico"
  117.       say "        fldunzip.ico"
  118.       say "        open-dir.cmd"
  119.       say "        od.cmd"
  120.       say "        kill-dir.cmd from" dir.found
  121.       Call SysFileDelete dir.found'wuz.cmd'
  122.       Call SysFileDelete dir.found'wuz.ico'
  123.       Call SysFileDelete dir.found'post-wuz.cmd'
  124.       Call SysFileDelete dir.found'zipstrip.cmd'
  125.       Call SysFileDelete dir.found'zip-dir.cmd'
  126.       Call SysFileDelete dir.found'zip-dir.ico'
  127.       Call SysFileDelete dir.found'fldzip.ico'
  128.       Call SysFileDelete dir.found'fldunzip.ico'
  129.       Call SysFileDelete dir.found'open-dir.cmd'
  130.       Call SysFileDelete dir.found'od.cmd'
  131.       Call SysFileDelete dir.found'kill-dir.cmd'
  132.       Call SysDestroyObject '<WorkplaceUnZip>'
  133.       Call SysDestroyObject '<ZipDir>'
  134.       if ans = 3 then exit(1)
  135.     end      
  136.     if ans=1 then
  137.       where = dir.found
  138.     leave
  139.   end
  140.  
  141.   if where = '' then do
  142.     i = i-1
  143.     root=FileSpec('Drive',Value('SYSTEM_INI',,'OS2ENVIRONMENT'))
  144.     base=1
  145.     nonbase=1
  146.     basedir. = ''
  147.     do j=1 to i
  148.       if Left(dir.j,6) = root'\OS2' | Left(dir.j,8) = root'\MMOS2' | dir.j = root'\' then do
  149.         basedir.base = dir.j
  150.     base = base+1
  151.       end
  152.       else do
  153.         dir.nonbase = dir.j
  154.         nonbase = nonbase+1
  155.       end
  156.     end
  157.     if base > 0 then do
  158.       k = 1
  159.       do j=nonbase to i
  160.         dir.j = basedir.k
  161.         k = k+1
  162.       end
  163.     end
  164.     dir.0 = i
  165.     tr = Trunc((i+1)/2)
  166.     do i=1 to tr
  167.       i2 = i+tr
  168.       build  = '('i')' dir.i
  169.       if dir.i2 \= '' then
  170.         build2 = '('i2')' dir.i2
  171.       else
  172.         build2 = ''
  173.       say insert(build,build2,,40)
  174.     end
  175.     Call CharOut ,'0a'x"Enter the number of your selection: "
  176.     parse pull ans
  177.     if ans > 0 & ans <= dir.0 then
  178.       where = dir.ans
  179.     else do
  180.       say "Invalid number.  Aborting"
  181.       exit(0)
  182.     end
  183.   end
  184.   tempdir = '\'
  185.   hold = directory()
  186. end
  187. else do
  188.   hold = directory()
  189.   where2 = directory(where)
  190.   if where2 = '\' then do
  191.     say "Unknown directory:" where
  192.     where = ''
  193.     Call Directory hold
  194.     Signal top
  195.   end
  196.   where = where2
  197.   tempdir = directory(tempdir)
  198. end
  199.  
  200. do while tempdir = '\'
  201.   temp = ''
  202.   if found > 0 then temp = old
  203.   if temp = '' then
  204.     temp = Value('TMP',,'OS2ENVIRONMENT')
  205.     if temp = '' then
  206.       temp = Value('TEMP',,'OS2ENVIRONMENT')
  207.   if SubStr(temp,2,1) != ':' then temp = ''
  208.   slash = 1
  209.   if Right(temp,1) = '/' then
  210.     temp = Left(temp,Length(temp)-1)
  211.   do while slash > 0
  212.     slash = LastPos('/',temp)
  213.     if slash > 0 then
  214.       temp = Left(temp,slash-1)'\'Right(temp,slash+1)
  215.   end
  216.   if temp = '' then
  217.     temp = Left(where,2)'\Temp'
  218.   Say "WUZ will create a temporary directory for each archive it extracts."
  219.   Call CharOut ,"Where should it create them? (<RETURN> for" temp") "
  220.   parse pull tempdir
  221.   if tempdir\='' then
  222.     temp = tempdir
  223.  
  224.   call Directory hold
  225.   tempdir = directory(temp)
  226.   if tempdir = '\' then do
  227.     Call CharOut ,temp "does not exist.  Should I create it? "
  228.     parse upper pull ans
  229.     if Left(ans,1) = 'Y' then do
  230.       if SysMkDir(temp) then
  231.         say "Can't create" temp
  232.       else
  233.         tempdir = temp
  234.     end
  235.   end
  236. end
  237.  
  238. call Directory hold
  239.  
  240. if where \= '.' then do
  241.   from = directory()
  242.   to = directory(where)
  243.   if to = '\' then do
  244.     say where': directory not found'
  245.     exit(1)
  246.   end
  247.   say '0a'x"Copying:    wuz.cmd"
  248.   say "        wuz.ico"
  249.   say "        post-wuz.cmd"
  250.   say "        zipstrip.cmd"
  251.   say "        zip-dir.cmd"
  252.   say "        zip-dir.ico"
  253.   say "        fldzip.ico"
  254.   say "        fldunzip.ico"
  255.   say "        open-dir.cmd"
  256.   say "        od.cmd"
  257.   say "        kill-dir.cmd to "to
  258.  
  259.   Drive = Left(tempdir,2)
  260.   Call SysFileDelete 'wuz.cmd'
  261.   Call LineOut 'WUZ.cmd',linein(from'wuz.cmd')
  262.   Call LineOut 'wuz.cmd',linein(from'wuz.cmd')
  263.   Call LineOut 'wuz.cmd',linein(from'wuz.cmd')
  264.   Call LineIn from'wuz.cmd'
  265.   Call LineIn from'wuz.cmd'
  266.   Call LineIn from'wuz.cmd'
  267.   Call LineIn from'wuz.cmd'
  268.   Call LineIn from'wuz.cmd'
  269.   Call LineIn from'wuz.cmd'
  270.   Call LineIn from'wuz.cmd'
  271.   Call LineOut 'wuz.cmd',"Drive    = '"Drive"'"
  272.   Call LineOut 'wuz.cmd',"DestPath = '"tempdir"'"
  273.   Call LineOut 'wuz.cmd',"IconPath = '"to"'"
  274.   Call LineOut 'wuz.cmd',""
  275.   Call LineOut 'wuz.cmd',"KeepCommandLineWindow =" KeepCommandLineWindow
  276.   Call LineOut 'wuz.cmd',"WaitForUnzip =" WaitForUnzip
  277.   Call LineOut 'wuz.cmd',"UnzipInCommandLineWindow =" UnzipInCommandLineWindow"    /* KeepCommandLineWindow must be 1 for this */"
  278.   do while lines(from'wuz.cmd') > 0
  279.     Call LineOut 'wuz.cmd',LineIn(from'wuz.cmd')
  280.   end
  281.   Call LineOut 'wuz.cmd'
  282.   '@copy' from'wuz.ico WUZ.ico > nul'
  283.  
  284.   if ucnt > 2 | final \= '' then do
  285.     Call SysFileDelete 'post-wuz.cmd'
  286.     Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.cmd')
  287.     Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.cmd')
  288.     Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.cmd')
  289.     Say ''
  290.     if final \= '' then do
  291.       Say "Preserving FinalCommand from" where"Post-WUZ.CMD"
  292.       Say final
  293.       Call LineIn from'Post-wuz.cmd'
  294.       Call LineOut 'Post-WUZ.cmd',final
  295.     end
  296.     else
  297.       Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.cmd')
  298.     if ucnt > 2 then do
  299.       Say "Preserving user lines from" where"Post-WUZ.CMD"
  300.       Call LineIn from'Post-wuz.cmd'
  301.       Call LineIn from'Post-wuz.cmd'
  302.       do i=1 to ucnt
  303.         Call LineOut 'Post-WUZ.cmd',user.i
  304.       end
  305.     end
  306.     else do
  307.       Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.cmd')
  308.       Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.cmd')
  309.     end
  310.     do while lines(from'Post-WUZ.cmd') > 0
  311.       Call LineOut 'Post-WUZ.cmd',LineIn(from'post-wuz.cmd')
  312.     end
  313.     Call LineOut 'Post-wuz.cmd'
  314.   end
  315.   else
  316.     '@copy' from'post-wuz.cmd > nul'
  317.  
  318.   '@copy' from'zipstrip.cmd > nul'
  319.   Call SysFileDelete 'zip-dir.cmd'
  320.   Call LineOut 'Zip-Dir.cmd',linein(from'zip-dir.cmd')
  321.   Call LineOut 'zip-dir.cmd',linein(from'zip-dir.cmd')
  322.   Call LineOut 'zip-dir.cmd',linein(from'zip-dir.cmd')
  323.   Call LineIn from'zip-dir.cmd'
  324.   Call LineOut 'zip-dir.cmd',"IconPath = '"to"'"
  325.   do while lines(from'zip-dir.cmd') > 0
  326.     Call LineOut 'zip-dir.cmd',LineIn(from'zip-dir.cmd')
  327.   end
  328.   '@copy' from'zip-dir.ico > nul'
  329.   '@copy' from'fldzip.ico > nul'
  330.   '@copy' from'fldunzip.ico > nul'
  331.   '@copy' from'open-dir.cmd > nul'
  332.   '@copy' from'open-dir.cmd OD.cmd > nul'
  333.   '@copy' from'kill-dir.cmd > nul'
  334.   Call Directory from
  335. end
  336. else
  337.   to = directory()
  338.  
  339. Call SysDestroyObject '<WorkplaceUnZip>'
  340. Call SysCreateObject "WPProgram", "WPS Unzip", "<WP_DESKTOP>",,
  341.     "OBJECTID=<WorkplaceUnZip>;PROGTYPE=WINDOWABLEVIO;EXENAME="to"wuz.cmd;ASSOCFILTER=*.arc,*.arj,*.lzh,*.tar,*.z,*.zif,*.zip,*.zoo"
  342. Call SysDestroyObject '<ZipDir>'
  343. here = directory()
  344. Call SysCreateObject "WPProgram", "Zip Directory", "<WP_DESKTOP>",,
  345.     "OBJECTID=<ZipDir>;PROGTYPE=WINDOWABLEVIO;EXENAME="to"zip-dir.cmd"
  346.  
  347. Say '0a'x"Workplace UnZip v1.1 has been successfully installed."
  348. Say "Try it out and see if you like it.  If you do, I would appreciate"
  349. Say "a small cash donation of $20 or at least a note telling me what"
  350. Say "you think.  My Usenet address is scott.maxwell@channel1.com."
  351. Say "Any money should go to:"
  352. Say "                         Pat Maxwell"
  353. Say "                         1587 E. Modesto Ave."
  354. Say "                         Camarillo, CA 93010 U.S.A."'0a'x
  355.  
  356. Say "You may also rerun Inst-WUZ.Cmd to uninstall."
  357. Say "For more information about Workplace UnZip, read ReadMe.WUZ and WUZ.Doc."
  358. exit(0)
  359.  
  360. Directory: procedure
  361.   arg Name
  362.   if Length(Name) > 3 then
  363.     if Right(Name,1) = '\' then
  364.       Name = Left(Name,LENGTH(Name)-1)
  365.   n = 'DIRECTORY'(Name)
  366.   if Right(n,1) \= '\' then
  367.     n = n'\'
  368.   return n
  369.